package com.sumainfor.pc.market.util;

import com.google.common.collect.Lists;
import com.sumainfor.common.config.SpringContextConfiguration;
import com.sumainfor.common.exception.TCException;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.pc.market.feign.GetUserInfoFeign;

import java.util.List;

/**
 * @Author Eddy·Chen
 * @Email 835033913@qq.com
 * @Create 2019-05-15 18:19
 */
public class FilterCenterUtil {

    /**
     * 筛选用户id
     *
     * @param uids
     * @param deptIds
     * @return
     */
    public static List<Integer> filterCenterUserId(List<Integer> uids, List<Integer> deptIds) {
        GetUserInfoFeign feign = SpringContextConfiguration.getApplicationContext().getBean(GetUserInfoFeign.class);
        List<Integer> resultIds = Lists.newArrayList();
        for (Integer uid : uids) {
            JsonResult<Integer> result = feign.getCenterServiceInfo(uid + "");
            if (result.isSuccess() == false) {
                throw new TCException("获取用户所属信息失败");
            }
            for (Integer deptId : deptIds) {
                if (deptId.equals(result.getResult())) {
                    resultIds.add(uid);
                    break;
                }
            }
        }
        return resultIds;
    }


    /**
     * 筛选用户id
     *
     * @param uids
     * @param deptIds
     * @return
     */
    public static List<Integer> yamengFilterCenterUserId(List<Integer> uids, List<Integer> deptIds) {
        GetUserInfoFeign feign = SpringContextConfiguration.getApplicationContext().getBean(GetUserInfoFeign.class);
        List<Integer> resultIds = Lists.newArrayList();
        for (Integer deptId : deptIds) {
            for (Integer uid : uids) {
                JsonResult<Integer> result = feign.getCenterServiceInfo(uid + "");
                if (result.isSuccess() == false) {
                    throw new TCException("获取用户所属信息失败");
                }
                if (deptId.equals(result.getResult())) {
                    resultIds.add(uid);
                }
            }
        }
        return resultIds;
    }
}
